package callgraph.process;

import callgraph.domain.JarConfig;
import callgraph.domain.ProfilingFilter;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.jar.JarFile;

abstract class CallGraphProcessor {
    /**
     * @deprecated 没啥用，标记是第几个jar包的
     */
    @Deprecated
    public static AtomicInteger jarNum = new AtomicInteger(0);

    protected CallGraphProcessStorage storage;
    protected ProfilingFilter profilingFilter;
    protected JarConfig jarConfig;
    protected JarFile jarFile;
    protected BufferedWriter resultWriter;

    public CallGraphProcessor(CallGraphProcessStorage storage, ProfilingFilter profilingFilter, JarConfig jarConfig, JarFile jarFile, BufferedWriter resultWriter) {
        this.storage = storage;
        this.profilingFilter = profilingFilter;
        this.jarConfig = jarConfig;
        this.jarFile = jarFile;
        this.resultWriter = resultWriter;
    }

    public CallGraphProcessStorage dumpStorage() {
        return storage;
    }

    public abstract boolean handle();

    public abstract CallGraphProcessor next();

    protected void writeResult(String data) {
        try {
            resultWriter.write(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
